package com.nickthorneltd.anchoralarm;

import java.io.IOException;
import java.util.List;

import android.location.Location;
import android.location.LocationManager;
import android.util.Log;

public class MockLocationProvider extends Thread {

    private List<String> data;
 
    private LocationManager locationManager;

    private String mocLocationProvider;

    private String LOG_TAG = "NickActivity";

    public MockLocationProvider(LocationManager locationManager,
            String mocLocationProvider, List<String> data) throws IOException {

        this.locationManager = locationManager;
        this.mocLocationProvider = mocLocationProvider;
        this.data = data;
    }

    
    @Override
  public  void run() {
          for (String str:data) {
 
 
              // Set one position
              String[] parts = str.split(",");
              Double latitude = Double.valueOf(parts[0]);
              Double longitude = Double.valueOf(parts[1]);
              Double altitude = Double.valueOf(parts[2]);
              Location location = new Location(mocLocationProvider);
              location.setLatitude(latitude);
              location.setLongitude(longitude);
              location.setAltitude(altitude);

              Log.e(LOG_TAG, location.toString());

              // set the time in the location. If the time on this location
              // matches the time on the one in the previous set call, it will be
              // ignored
              location.setTime(System.currentTimeMillis());

              locationManager.setTestProviderLocation(mocLocationProvider,
                      location);
           	  try {

                  Thread.sleep(2000);

              } catch (InterruptedException e) {

                  e.printStackTrace();
              }
          
          }
        }

}